﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity.Migrations;
using _1._8._2015_KidChores.Data.Models;

namespace _1._8._2015_KidChores.Data
{
    public static class Seeder
    {
        public static void Seed(KidChoreDbContext db)
        {
            // First Seed Child(s) then seed Chore(s) they don't have dependancies, last seed KidChore(s) since it depends on kid and chore
            Kid kid1 = new Kid
                {
                   FirstName = "Jettin",
                   LastName = "Murphy"
                };

            Kid kid2 = new Kid
                {
                    FirstName = "Maverick",
                    LastName = "Murphy"
                };
   
            db.Kids.AddOrUpdate(kid1, kid2);
   
            db.SaveChanges();

            kid1 = db.Kids.FirstOrDefault(k => k.FirstName == "Jettin");
            kid2 = db.Kids.FirstOrDefault(k => k.FirstName == "Maverick");


            Chore chore1 = new Chore 
            {
                Description = "Clean Room"
            };
            Chore chore2 = new Chore
            {
                Description = "Feed Dogs"
            };
            Chore chore3 = new Chore
            {
                Description = "Feed Cats"
            };

            db.Chores.AddOrUpdate(chore1, chore2, chore3);
            db.SaveChanges();

            chore1 = db.Chores.FirstOrDefault(c => c.Description == "Clean Room");
            chore2 = db.Chores.FirstOrDefault(c => c.Description == "Feed Dogs");
            chore3 = db.Chores.FirstOrDefault(c => c.Description == "Feed Cats");


            db.KidChores.AddOrUpdate(kc => new { kc.KidId, kc.ChoreId },
            new KidChore
                {
                    KidId = kid1.KidId,
                    ChoreId = chore1.ChoreId
                },
            new KidChore
                {
                    KidId = kid1.KidId,
                    ChoreId = chore3.ChoreId
                },
            new KidChore
                {
                    KidId = kid2.KidId,
                    ChoreId = chore1.ChoreId
                },
            new KidChore
                {
                    KidId = kid2.KidId,
                    ChoreId = chore2.ChoreId
                }
                );
            db.SaveChanges();

        }
    }
}
